Make modtools/create-unit Steam-arena compatible and add spawn-unit delegator#21
Make modtools/create-unit Steam-arena compatible and add spawn-unit delegator#21unboundlopez wants to merge 2 commits intocreate-unitfrom
modtools/create-unit Steam-arena compatible and add spawn-unit delegator#21Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 745262ed38
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not spawnOpen then | ||
| break |
There was a problem hiding this comment.
Fail loudly when arena menu cannot be opened
In createUnitInner, if neither arena-open key can be injected, the code just breaks out of the spawn loop and returns whatever was created so far (often zero) without an error. That turns an environment/keybinding incompatibility into a silent under-spawn, which is especially misleading for callers like spawn-unit that treat a returned table as success. This path should raise a diagnostic instead of silently exiting.
Useful? React with 👍 / 👎.
| if not selected then | ||
| pcall(function() gui.simulateInput(spawnScreen, {SELECT=true}) end) |
There was a problem hiding this comment.
Stop processing when creature SELECT input fails
If SELECT fails, the fallback pcall result is ignored and execution continues as if a creature was spawned. In that failure case, the subsequent df.unit.find(df.global.unit_next_id-1) can point to a pre-existing unit, so processNewUnit(...) may mutate the wrong creature (nickname/domestication/flags), corrupting game state. The spawn path should verify that selection succeeded (or that a new unit id was allocated) before continuing.
Useful? React with 👍 / 👎.
Motivation
modtools/create-unitis invoked on Steam DFHack builds that expose arena state under a different field layout.spawn-unitwrapper that preserves interactive flow while delegating actual unit creation to the Steam-awaremodtools/create-unitimplementation.Description
modtools/create-unit.luato preferdf.global.world.arena_spawnand fall back todf.global.world.arena, andqerrorif no arena spawn state is available.type,filter,interaction,tame) with nil checks and only restore them if previously saved, preventing nil-index crashes on Steam layouts.ARENA_CREATE_CREATUREfirst thenD_LOOK_ARENA_CREATURE, and use a table-formSELECTfallback when directSELECTdelivery fails.spawn-unit.luascript that provides an interactive list/input prompt flow, validates fortress mode and cursor position, validates race/caste andcount, and delegates spawning tocreate_unit.createUnit(...)inside apcall, exposingdo_spawnwhen loaded as a module (dfhack_flags.module).Testing
rgconfirmed thearena_spawnfallback and the key/input fallbacks are present inmodtools/create-unit.lua(succeeded).nl/sedverified the guarded field handling and the new spawn-flow code paths are present (succeeded).Codex Task